/**
 * Created by zhr on 2017/6/27.
 */
import React from "react";
import Relay from 'react-relay';
import { message } from 'antd';
import Util from "../../../../../../../util/Util";
import { Button, Modal, Input } from 'fly';
import './common.css';
import Config from "../../../../../../../util/Config"

export default class Tab extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            historyVisible: false,
            historyList:null
        }
        this.url = Config.qiuniu;
        this.handleOk = this.handleOk.bind(this);
        this.handleCancel = this.handleCancel.bind(this);
    }

    handleOk() {
        this.setState({
            historyVisible: false,
        });
    }
    handleCancel() {
        this.setState({
            historyVisible: false,
        })
    }
    fileDownload(v) {
        // Array.isArray(JSON.parse(v)) && JSON.parse(v).forEach((i, k) => {
        const h = this.url + v.response.key + `?attname=`+ v.name, a = document.createElement("a");
        a.href = h;
        a.setAttribute("download","");
        a.click();
        // });
    }
    showFile(fileJSON) {
       return fileJSON ? (
            JSON.parse(fileJSON).map((f,c)=>{
                return (
                    <span className="settlementView_for">
                        <a style={{cursor:'default'}}>{f.name}</a>
                        {
                            f.response ? (<a onClick={this.fileDownload.bind(this,f)} style={{minWidth:'30px',color:'#36b3b3',paddingLeft: '0',marginLeft: '50px'}}>下载</a>) : null
                        }
                    </span>)
            })
        ) : '无'
    }
    render() {
        const {historyList} = this.state;
        return (
            <div className="">
                <Modal
                    title="历史审批列表"
                    visible={this.state.historyVisible}
                    onOk={this.handleOk}
                    onCancel={this.handleCancel}
                    footer={null}
                >
                    <div>
                        {
                            historyList && historyList.length ? historyList.map((v,i)=>{
                                return (
                                    <div className="reply_box history_box">
                                        <p>
                                            <span>时&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 间：</span>
                                            <span>{Util.dateFormat(v.examineDate)}</span>
                                        </p>
                                        <p>
                                            <span>企&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 业：</span>
                                            <span>{v.examineCompany}</span>
                                        </p>
                                        <p>
                                            <span>批复结果：</span>
                                            <span>{v.result == 1 ? '接受' :'不接受'}</span>
                                        </p>
                                        <p>
                                            <span style={{float:'left'}}>批复报告：</span>
                                            <span>
                                                {
                                                   this.showFile(v.fileJSON)
                                                }
                                            </span>
                                        </p>
                                        <p>
                                            <span>批复说明：</span>
                                            <span>{v.explainDesc || '无'}</span>
                                        </p>
                                        {
                                            historyList.length > 1 && i != historyList.length - 1 ? (
                                                <p className={ i < historyList.length-1 && historyList[i].version != historyList[i+1].version ? 'history_bottom_solid' : 'history_bottom_dashed'}></p>
                                            ) : null
                                        }
                                    </div>
                                )
                            }) : null
                        }
                    </div>
                </Modal>
            </div>
        )
    }
}